﻿using System;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Common;

namespace TRPOP.CRM.Web
{
    public partial class Employee_list : BaseAdmin
    {
        #region 权限限制
        protected override void SubPageInit()
        {
            base.m_oCurrentPermissionKey = "Employee_Employee";
        }
        #endregion

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        /// <summary>
        /// 分页触发此事件（分页采用post方法传递数据）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void UC_PagerChanged(object sender, EventArgs e)
        {
            BindData();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (!txtName.Text.IsEmpty() && txtName.Text != "输入员工姓名")
            {
                ViewState["SearchCondation"] = string.Format("AND nvcEmployeeName LIKE '%{0}%' ", txtName.Text.Trim().HtmlEncode().SQLFilter());
            }
            else
            {
                ViewState["SearchCondation"] = string.Empty;
            }

            Pager.Page_ReLoad();

            BindData();
        }

        /// <summary>        
        /// 删除管理员信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            LinkButton lbtn = (LinkButton)sender;

            if (EmployeeManage.DeleteInfoById(lbtn.CommandArgument.ToInt()))
            {
                Alert("删除成功！");
            }
            else
            {
                Alert("删除失败，请先删除与该用户相关的数据信息");
            }

            Pager.Page_ReLoad();
            BindData();
        }

        /// <summary>
        /// 批量删除管理员信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strRegiterIds = RequestHelper.RequestString("delid");

            if (strRegiterIds.IsEmpty())
            {
                return;
            }

            if (EmployeeManage.DeleteInfoByIds(strRegiterIds))
            {
                Alert("所选信息的已删除");
            }
            else
            {
                Alert("删除失败，请先删除与所选用户相关的数据信息");
            }

            Pager.Page_ReLoad();
            BindData();
        }
        #endregion

        #region 页面方法
        /// <summary>
        /// 绑定管理员信息列表
        /// </summary>
        protected void BindData()
        {
            int RecordCount = 0;

            string strCondition = string.Empty;
            if (ViewState["SearchCondation"] != null)
            {
                strCondition = ViewState["SearchCondation"].ToString();
            }

            rptList.DataSource = EmployeeManage.GetEmployeeSimpleInfoPager(Pager.CurrentPage, Pager.PageSize, strCondition, string.Empty, out RecordCount);

            rptList.DataBind();

            Pager.RecordCount = RecordCount;
        }
        #endregion
    }
}